﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;
using FinPlusInterfaces;

namespace FinPlusCompView
{
    public class FinPlusGridColTriState : FinPlusGridColBase
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }

        //construct
        public FinPlusGridColTriState(string name, CheckBox filterCheck, bool hasFilter = false, bool isEnabled = false)
        {
            var tb = new FrameworkElementFactory(typeof(FinPlusValueTriState));
            tb.SetBinding(FinPlusValueTriState.IdProperty, new Binding(BeanField.Id.ToString()) { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetBinding(FinPlusValueTriState.ValueProperty, new Binding(BeanField.Value.ToString()) { Mode = BindingMode.OneWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
            tb.SetBinding(FinPlusValueTriState.StateProperty, new Binding(name) { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });

            var dt = new DataTemplate() { VisualTree = tb };
            Header = hasFilter ? HeaderFilterCheck(name, filterCheck) : (object)name;
            CellTemplate = dt;
            ClipboardContentBinding = new Binding(name) { Mode = BindingMode.OneWay };
            SortMemberPath = name;
            CanUserSort = true;
        }
    }
}
